<div class="sm-rightPanel bg-darken">
    <div class="layui-anim layui-anim-upbit">
        <blockquote class="site-text layui-elem-quote">
            品牌介绍
        </blockquote>
        <div class="layui-form" action="">
            <div class="layui-row">
                <div class="sm-form-lg" id="dialog_form" style="overflow: hidden;">
                    <input type="hidden" name="id" value="">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i>*</i>内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" id="content" cols="30" rows="10"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit lay-filter="addsingle_form">立即提交</button>
                            <button type="button" class="layui-btn  layui-btn-primary" id="add_canl">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layedit', "upload", "form"], function () {
        var layedit = layui.layedit;
        var $ = layui.$;
        var upload = layui.upload;
        var form = layui.form;
        var layeditIndex;
        form.render();

        // 设置富文本上传接口
        layedit.set({
            uploadImage: {
                url: '/managerImg/uploadFile',
                type: 'post'
            },
            uploadVideo: {
                url: '/managerImg/uploadFile',
                type: 'post'
            },
            uploadAudio: {
                url: '/managerImg/uploadFile',
                type: 'post'
            },
        });

        initData();
        //取消
        $("#add_canl").click(function () {

        });
        //提交
        form.on('submit(addsingle_form)', function (d) {
            var formData = d.field;
            var data = {};
            data.id = formData.id;
            data.title = formData.title;
            data.content = layedit.getContent(layeditIndex);
            smartAui.ajax({
                url: '/websitebrandintroduction/save',
                data: data,
                loading: true,
                success: function (result) {
                    if (result.success) {
                        layer.msg("保存成功");
                    }
                },
            });
            return false;
        });
        //上传
        upload.render({
            elem: '#uploader',
            url: '/mediaFile/addMateria',
            data: {type: 'thumb'},//缩略图
            size: 64,
            accept: "images",
            exts: 'JPG|jpg',
            before: function () {
                smartAui.loading();
            },
            done: function (result) {
                layer.closeAll('loading');
                if (result.success) {
                    $("#uploader").html("<img src='" + result.data.url + "' style='width: 150px;height: 150px;'/><p>点击重新上传，或将文件拖拽到此处</p>");
                    $("#add_picpath").val(result.data.url);
                    $("#add_thumbMediaId").val(result.data.imgMediaId);
                    $(".wxmp-doclist .main img").attr("src", result.data.url);
                } else {
                    layer.msg("上传接口异常");
                }
            },
            error: function () {
                layer.closeAll('loading');
                layer.msg(result.msg || "上传接口异常");
            }
        });

        function initData() {
            smartAui.ajax({
                url: '/websitebrandintroduction/info',
                success: function (result) {
                    if (result.success && result.data) {
                        var id = result.data.id;
                        var content = result.data.content;
                        $("input[name='id']").val(id);
                        $("#content").text(content);
                    }
                    layeditIndex = layedit.build('content', {
                        tool: ['strong', 'italic', 'underline', 'del'
                            , '|'
                            , 'left', 'center', 'right'
                            , '|'
                            , 'link', 'unlink', 'face', "code",
                            '|',
                            'image'
                        ]
                    });
                },
            });
        }

    });
</script>